<?php

/*
 * File  : galeri.php
 * Table : galeris, kategori_galeris
 */
//session_start();
//cek session

if ((!$_SESSION["USRID"] AND !$_SESSION["USRPASS"])) {
    header("location: ../index.php");
    exit();
}
//end
?>

<?php

$aksi = "cms/app/m_galeris/aksi_galeri.php";
switch ($_GET["opr"]) {

// tampil galeri
    default:
        echo "<h2>Galeri</h2>";
        echo " <input type=button value='Tambah Galeri' onclick=\"window.location.href='?module=galeri&opr=tambah';\">";
        echo " <table>";
        echo "  <tr><th>No</th><th>Kategori</th><th>Judul</th><th>Gambar</th><th>Status</th><th>Aksi</th></tr>";

        $p = new Paging;
        $batas = 10;
        $posisi = $p->cariPosisi($batas);

        $tampil = mysql_query("SELECT * FROM galeris ORDER BY galeri_id DESC LIMIT $posisi, $batas");

        $no = $posisi + 1;
        while ($row = mysql_fetch_array($tampil)) {
            echo "<tr><td>$no</td>";
            echo " <td>" . get_kategori_galeri_nama_from_id($row["galeri_kategori_id"]) . "</td>";
            echo " <td>" . $row["galeri_nama"] . "</td>";
            echo " <td><img src = '../media/galeri/small_" . $row["galeri_gambar"] . "'></td>";
            if ($row["galeri_status"] == 1) {
                echo " <td><a href='" . URLHOST . "$aksi?module=galeri&opr=update_status&id=" . $row["galeri_id"] . "&status=" . $row["galeri_status"] . "'>Aktif</a></td>";
            } else {
                echo " <td><a href='" . URLHOST . "$aksi?module=galeri&opr=update_status&id=" . $row["galeri_id"] . "&status=" . $row["galeri_status"] . "'>Tidak Aktif</a></td>";
            }
            echo " <td><a href='?module=galeri&opr=edit&id=" . $row["galeri_id"] . "'>Edit</a> | 
		                <a href='" . URLHOST . "$aksi?module=galeri&opr=hapus&id=" . $row["galeri_id"] . "'  onClick=\"return confirm('Hapus galeri " . $row["galeri_nama"] . "?')\" >Hapus</a>";
            echo " </td></tr>";
            $no++;
        }
        echo "</table>";

        $jmldata = mysql_num_rows(mysql_query("SELECT * FROM galeris"));
        $jmlhalaman = $p->jumlahHalaman($jmldata, $batas);
        $linkHalaman = $p->navHalaman($_GET["halaman"], $jmlhalaman);

        echo "<div id=paging>Hal: $linkHalaman</div><br>";
        break;

// tambah galeri
    case "tambah":
        load_tinymce();
        echo "<h2>Tambah Galeri</h2>";
        echo " <form method='POST' action='" . URLHOST . "$aksi?module=galeri&opr=input' enctype='multipart/form-data'>";
        echo " <table>";
        echo "  <tr><td>Judul</td><td> : <input type='text' name='in_galeri_nama' size='60'></td></tr>";
        echo "  <tr><td>Kategori</td>  <td> :";
        echo "   <select name='in_galeri_kategori_id'>";
        echo "    <option value='0' selected>- Pilih Kategori -</option>";
        $tampil = mysql_query("SELECT * FROM kategori_galeris ORDER BY kategori_nama");
        while ($row = mysql_fetch_array($tampil)) {
            echo "<option value='" . $row["kategori_id"] . "'>" . $row["kategori_nama"] . "</option>";
        }
        echo "   </select></td></tr>";
        echo "  <tr><td>Deskripsi</td><td> <textarea name = 'in_galeri_deskripsi' style = 'width: 600px; height: 350px;'></textarea></td></tr>";
        echo "  <tr><td>Status</td><td> : <input type='radio' name='in_galeri_status' value='1' checked>Aktif &nbsp; <input type='radio' name='in_galeri_status' value='0'>Tidak Aktif</td></tr>";
        echo "  <tr><td>Gambar</td><td> : <input type = file name = 'in_galeri_gambar' size = 40>";
        echo "  <br>Tipe gambar harus JPG/JPEG dan ukuran lebar maks: 400 px</td></tr>";
        echo "  <tr><td colspan='2'><input type ='submit' value ='Simpan'>";
        echo "  <input type ='button' value ='Batal' onclick ='self.history.back()'></td></tr>";
        echo " </table>";
        echo " </form>";
        break;

    case "edit":
        $edit = mysql_query("SELECT * FROM galeris WHERE galeri_id = '" . $_GET["id"] . "'");
        $row = mysql_fetch_array($edit);

        load_tinymce();
        echo "<h2>Edit Galeri</h2>";
        echo " <form method='POST' action ='" . URLHOST . "$aksi?module=galeri&opr=update' enctype='multipart/form-data'>";
        echo " <input type ='hidden' name ='id' value ='" . $row["galeri_id"] . "'>";
        echo " <table>";
        echo "  <tr><td>Nama galeri</td> <td> : <input type='text' name = 'in_galeri_nama' size ='60' value = '" . $row["galeri_nama"] . "'></td></tr>";
        echo "  <tr><td>Kategori</td> <td> : <select name = 'in_galeri_kategori_id'>";

        $tampil = mysql_query("SELECT * FROM kategori_galeris ORDER BY kategori_nama");
        if ($row["galeri_kategori_id"] == 0) {
            echo "<option value = 0 selected>- Pilih Kategori -</option>";
        }

        while ($w = mysql_fetch_array($tampil)) {
            if ($row["galeri_kategori_id"] == $w["kategori_id"]) {
                echo "<option value ='" . $w["kategori_id"] . "' selected>" . $w["kategori_nama"] . "</option>";
            } else {
                echo "<option value ='" . $w["kategori_id"] . "'>" . $w["kategori_nama"] . "</option>";
            }
        }
        echo "  </select></td></tr>";
        echo "  <tr><td>Deskripsi</td> <td> <textarea name = 'in_galeri_deskripsi' style = 'width: 600px; height: 350px;'>" . $row["galeri_deskripsi"] . "</textarea></td></tr>";
        echo "  <tr><td>Status</td><td> : <input type='radio' name='in_galeri_status' value='1' " . ($row["galeri_status"] == 1 ? "checked" : "") . ">Aktif &nbsp; <input type='radio' name='in_galeri_status' value='0' " . ($row["galeri_status"] == 0 ? "checked" : "") . ">Tidak Aktif</td></tr>";
        echo "  <tr><td>Gambar</td> <td> : <img src = '../media/galeri/small_" . $row["galeri_gambar"] . "'></td></tr>";
        echo "  <tr><td>Ganti Gbr</td> <td> : <input type ='file' name = 'in_galeri_gambar' size = '30'> *)</td></tr>";
        echo "  <tr><td colspan = 2>*) Apabila gambar tidak diubah, dikosongkan saja.</td></tr>";
        echo "  <tr><td colspan = 2><input type ='submit' value ='Update'><input type ='button' value ='Batal' onclick = self.history.back()></td></tr>";
        echo "  </table></form>";
        break;
}
?>
